//
//  ASAddResearchVC.m
//  AttendenceSys
//
//  Created by 窦芳俊 on 16/4/13.
//  Copyright © 2016年 窦芳俊. All rights reserved.
//

#import "ASAddResearchPaperVC.h"
#import "FTPhotoAlbumController.h"
#import "FTAlbumPhotosController.h"

@interface ASAddResearchPaperVC ()

@end

@implementation ASAddResearchPaperVC

- (instancetype)initWithTypeId:(NSInteger)typeId
                  researchType:(NSString *)rType
                     rTypeInfo:(ASResearchTypeInfo*)typeInfo
{
    self = [super init];
    if (self)
    {
        _typeID = typeId;
        _resTypeName = rType;
        _rTypeInfo = typeInfo;
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    _releaseArrImage = [[NSMutableArray alloc] init];
    
    self.strNavTitle = _resTypeName;
    [self setRightText:@"保存"];
    
    [self initUI];
}

- (void)initUI
{
    if ([_resTypeName isEqualToString:@"论文"])
    {
        [self initPaperUI];
    }
    else
    {
        [self initOriginalUI];
    }
}

- (void)initPaperUI
{
    ///////论文
    //论文名称
    //期刊名称
    //发表时间
    //论文类别：一级权威、二级权威、CSSCI、CSSCI扩展、中文核心、国际期刊、省级期刊、其他刊物。
    //作者排名：第一作者、第二作者、第二作者导师第一作者
    //论文描述
    
    CGFloat padding = 10.0f;
    // 论文名称
    _researchName = [[UILabel alloc] initWithFrame:CGRectMake(padding, 20, 70, 20)];
    _researchName.font = [UIFont systemFontOfSize:16];
    _researchName.text = @"论文名称:";
    [_researchName setTextAlignment:NSTextAlignmentLeft];
    _researchName.textColor = [UIColor colorWithRed:102.0/255.0 green:102.0/255.0 blue:102.0/255.0 alpha:1.0];
    [self.view addSubview:_researchName];
    
    _inputresearchName = [[UITextField alloc] initWithFrame:CGRectMake(_researchName.frame.origin.x + _researchName.frame.size.width + 5,
                                                                       _researchName.frame.origin.y,
                                                                       self.view.frame.size.width - 80 - 10,
                                                                       20)];
    _inputresearchName.clearButtonMode = UITextFieldViewModeWhileEditing;
    _inputresearchName.textColor = [UIColor blackColor];
    _inputresearchName.returnKeyType = UIReturnKeyDone;
    _inputresearchName.placeholder = @"输入论文名称";
    [_inputresearchName setBackgroundColor:[UIColor clearColor]];
    _inputresearchName.delegate = self;
    _inputresearchName.font = [UIFont systemFontOfSize:16.0f];
    _inputresearchName.borderStyle = UITextBorderStyleNone;
    [self.view addSubview:_inputresearchName];
    
    // 期刊名称
    _researchType = [[UILabel alloc] initWithFrame:CGRectZero];
    _researchType.frame = CGRectMake(padding, _researchName.frame.origin.y + _researchName.frame.size.height + 18, 70, 20);
    _researchType.font = [UIFont systemFontOfSize:16];
    _researchType.text = @"期刊名称:";
    [_researchType setTextAlignment:NSTextAlignmentLeft];
    _researchType.textColor = [UIColor colorWithRed:102.0/255.0 green:102.0/255.0 blue:102.0/255.0 alpha:1.0];
    [self.view addSubview:_researchType];
    
    _inputresearchType = [[UITextField alloc] initWithFrame:CGRectMake(_researchType.frame.origin.x + _researchType.frame.size.width + 5,
                                                                       _researchType.frame.origin.y,
                                                                       self.view.frame.size.width - 80 - 10,
                                                                       20)];
    _inputresearchType.clearButtonMode = UITextFieldViewModeWhileEditing;
    _inputresearchType.textColor = [UIColor blackColor];
    _inputresearchType.returnKeyType = UIReturnKeyDone;
    _inputresearchType.placeholder = @"输入期刊名称";
    [_inputresearchType setBackgroundColor:[UIColor clearColor]];
    _inputresearchType.delegate = self;
    _inputresearchType.font = [UIFont systemFontOfSize:16.0f];
    _inputresearchType.borderStyle = UITextBorderStyleNone;
    [self.view addSubview:_inputresearchType];
    
    // 发表时间
    _researchTime = [[UILabel alloc] initWithFrame:CGRectZero];
    _researchTime.frame = CGRectMake(padding, _researchType.frame.origin.y + _researchType.frame.size.height + 18, 70, 20);
    _researchTime.font = [UIFont systemFontOfSize:16];
    _researchTime.text = @"发表时间:";
    [_researchTime setTextAlignment:NSTextAlignmentLeft];
    _researchTime.textColor = [UIColor colorWithRed:102.0/255.0 green:102.0/255.0 blue:102.0/255.0 alpha:1.0];
    [self.view addSubview:_researchTime];
    
    _inputresearchTime = [[UITextField alloc] initWithFrame:CGRectMake(_researchTime.frame.origin.x + _researchTime.frame.size.width + 5,
                                                                       _researchTime.frame.origin.y,
                                                                       self.view.frame.size.width - 80 - 10,
                                                                       20)];
    _inputresearchTime.clearButtonMode = UITextFieldViewModeWhileEditing;
    _inputresearchTime.textColor = [UIColor blackColor];
    _inputresearchTime.returnKeyType = UIReturnKeyDone;
    _inputresearchTime.placeholder = @"输入发表时间";
    [_inputresearchTime setBackgroundColor:[UIColor clearColor]];
    _inputresearchTime.delegate = self;
    _inputresearchTime.font = [UIFont systemFontOfSize:16.0f];
    _inputresearchTime.borderStyle = UITextBorderStyleNone;
    [self.view addSubview:_inputresearchTime];
    
    // 论文类别
    _researchLevel = [[UILabel alloc] initWithFrame:CGRectZero];
    _researchLevel.frame = CGRectMake(padding, _researchTime.frame.origin.y + _researchTime.frame.size.height + 18, 70, 20);
    _researchLevel.font = [UIFont systemFontOfSize:16];
    _researchLevel.text = @"论文类别:";
    [_researchLevel setTextAlignment:NSTextAlignmentLeft];
    _researchLevel.textColor = [UIColor colorWithRed:102.0/255.0 green:102.0/255.0 blue:102.0/255.0 alpha:1.0];
    [self.view addSubview:_researchLevel];
    
    _inputresearchLevel = [[UITextField alloc] initWithFrame:CGRectMake(_researchLevel.frame.origin.x + _researchLevel.frame.size.width + 5,
                                                                        _researchLevel.frame.origin.y,
                                                                        self.view.frame.size.width - 80 - 10,
                                                                        20)];
    _inputresearchLevel.clearButtonMode = UITextFieldViewModeWhileEditing;
    _inputresearchLevel.textColor = [UIColor blackColor];
    _inputresearchLevel.returnKeyType = UIReturnKeyDone;
    _inputresearchLevel.placeholder = @"输入论文类别";
    [_inputresearchLevel setBackgroundColor:[UIColor clearColor]];
    _inputresearchLevel.delegate = self;
    _inputresearchLevel.font = [UIFont systemFontOfSize:16.0f];
    _inputresearchLevel.borderStyle = UITextBorderStyleNone;
    [self.view addSubview:_inputresearchLevel];
    
    // 作者排名
    _researchDesc = [[UILabel alloc] initWithFrame:CGRectZero];
    _researchDesc.frame = CGRectMake(padding, _researchLevel.frame.origin.y + _researchLevel.frame.size.height + 18, 70, 20);
    _researchDesc.font = [UIFont systemFontOfSize:16];
    _researchDesc.text = @"作者排名:";
    [_researchDesc setTextAlignment:NSTextAlignmentLeft];
    _researchDesc.textColor = [UIColor colorWithRed:102.0/255.0 green:102.0/255.0 blue:102.0/255.0 alpha:1.0];
    [self.view addSubview:_researchDesc];
    
    _inputresearchDesc = [[UITextField alloc] initWithFrame:CGRectMake(_researchDesc.frame.origin.x + _researchDesc.frame.size.width + 5,
                                                                       _researchDesc.frame.origin.y,
                                                                       self.view.frame.size.width - 80 - 10,
                                                                       20)];
    _inputresearchDesc.clearButtonMode = UITextFieldViewModeWhileEditing;
    _inputresearchDesc.textColor = [UIColor blackColor];
    _inputresearchDesc.returnKeyType = UIReturnKeyDone;
    _inputresearchDesc.placeholder = @"输入作者排名";
    [_inputresearchDesc setBackgroundColor:[UIColor clearColor]];
    _inputresearchDesc.delegate = self;
    _inputresearchDesc.font = [UIFont systemFontOfSize:16.0f];
    _inputresearchDesc.borderStyle = UITextBorderStyleNone;
    [self.view addSubview:_inputresearchDesc];
    
    // 论文描述
    _researchComment = [[UILabel alloc] initWithFrame:CGRectZero];
    _researchComment.frame = CGRectMake(padding, _researchDesc.frame.origin.y + _researchDesc.frame.size.height + 18, 70, 20);
    _researchComment.font = [UIFont systemFontOfSize:16];
    _researchComment.text = @"论文描述:";
    [_researchComment setTextAlignment:NSTextAlignmentLeft];
    _researchComment.textColor = [UIColor colorWithRed:102.0/255.0 green:102.0/255.0 blue:102.0/255.0 alpha:1.0];
    [self.view addSubview:_researchComment];
    
    _inputresearchComment = [[UITextField alloc] initWithFrame:CGRectMake(_researchComment.frame.origin.x + _researchComment.frame.size.width + 5,
                                                                          _researchComment.frame.origin.y,
                                                                          self.view.frame.size.width - 80 - 10,
                                                                          20)];
    _inputresearchComment.clearButtonMode = UITextFieldViewModeWhileEditing;
    _inputresearchComment.textColor = [UIColor blackColor];
    _inputresearchComment.returnKeyType = UIReturnKeyDone;
    _inputresearchComment.placeholder = @"输入论文描述";
    [_inputresearchComment setBackgroundColor:[UIColor clearColor]];
    _inputresearchComment.delegate = self;
    _inputresearchComment.font = [UIFont systemFontOfSize:16.0f];
    _inputresearchComment.borderStyle = UITextBorderStyleNone;
    [self.view addSubview:_inputresearchComment];
    
    [self initScrollView:_releaseArrImage];
}

- (void)initOriginalUI
{
    CGFloat padding = 10.0f;
    // 科研名称
    _researchName = [[UILabel alloc] initWithFrame:CGRectMake(padding, 20, 70, 20)];
    _researchName.font = [UIFont systemFontOfSize:16];
    _researchName.text = @"科研名称:";
    [_researchName setTextAlignment:NSTextAlignmentLeft];
    _researchName.textColor = [UIColor colorWithRed:102.0/255.0 green:102.0/255.0 blue:102.0/255.0 alpha:1.0];
    [self.view addSubview:_researchName];
    
    _inputresearchName = [[UITextField alloc] initWithFrame:CGRectMake(_researchName.frame.origin.x + _researchName.frame.size.width + 5,
                                                                       _researchName.frame.origin.y,
                                                                       self.view.frame.size.width - 80 - 10,
                                                                       20)];
    _inputresearchName.clearButtonMode = UITextFieldViewModeWhileEditing;
    _inputresearchName.textColor = [UIColor blackColor];
    _inputresearchName.returnKeyType = UIReturnKeyDone;
    _inputresearchName.placeholder = @"输入科研名称";
    [_inputresearchName setBackgroundColor:[UIColor clearColor]];
    _inputresearchName.delegate = self;
    _inputresearchName.font = [UIFont systemFontOfSize:16.0f];
    _inputresearchName.borderStyle = UITextBorderStyleNone;
    [self.view addSubview:_inputresearchName];
    
    // 科研类型
    _researchType = [[UILabel alloc] initWithFrame:CGRectZero];
    _researchType.frame = CGRectMake(padding, _researchName.frame.origin.y + _researchName.frame.size.height + 18, 70, 20);
    _researchType.font = [UIFont systemFontOfSize:16];
    _researchType.text = @"科研类型:";
    [_researchType setTextAlignment:NSTextAlignmentLeft];
    _researchType.textColor = [UIColor colorWithRed:102.0/255.0 green:102.0/255.0 blue:102.0/255.0 alpha:1.0];
    [self.view addSubview:_researchType];
    
    _inputresearchType = [[UITextField alloc] initWithFrame:CGRectMake(_researchType.frame.origin.x + _researchType.frame.size.width + 5,
                                                                       _researchType.frame.origin.y,
                                                                       self.view.frame.size.width - 80 - 10,
                                                                       20)];
    _inputresearchType.clearButtonMode = UITextFieldViewModeWhileEditing;
    _inputresearchType.textColor = [UIColor blackColor];
    _inputresearchType.returnKeyType = UIReturnKeyDone;
    _inputresearchType.placeholder = @"输入科研类型";
    [_inputresearchType setBackgroundColor:[UIColor clearColor]];
    _inputresearchType.delegate = self;
    _inputresearchType.font = [UIFont systemFontOfSize:16.0f];
    _inputresearchType.borderStyle = UITextBorderStyleNone;
    [self.view addSubview:_inputresearchType];
    
    // 科研时间
    _researchTime = [[UILabel alloc] initWithFrame:CGRectZero];
    _researchTime.frame = CGRectMake(padding, _researchType.frame.origin.y + _researchType.frame.size.height + 18, 70, 20);
    _researchTime.font = [UIFont systemFontOfSize:16];
    _researchTime.text = @"科研时间:";
    [_researchTime setTextAlignment:NSTextAlignmentLeft];
    _researchTime.textColor = [UIColor colorWithRed:102.0/255.0 green:102.0/255.0 blue:102.0/255.0 alpha:1.0];
    [self.view addSubview:_researchTime];
    
    _inputresearchTime = [[UITextField alloc] initWithFrame:CGRectMake(_researchTime.frame.origin.x + _researchTime.frame.size.width + 5,
                                                                       _researchTime.frame.origin.y,
                                                                       self.view.frame.size.width - 80 - 10,
                                                                       20)];
    _inputresearchTime.clearButtonMode = UITextFieldViewModeWhileEditing;
    _inputresearchTime.textColor = [UIColor blackColor];
    _inputresearchTime.returnKeyType = UIReturnKeyDone;
    _inputresearchTime.placeholder = @"输入科研时间";
    [_inputresearchTime setBackgroundColor:[UIColor clearColor]];
    _inputresearchTime.delegate = self;
    _inputresearchTime.font = [UIFont systemFontOfSize:16.0f];
    _inputresearchTime.borderStyle = UITextBorderStyleNone;
    [self.view addSubview:_inputresearchTime];
    
    // 科研级别
    _researchLevel = [[UILabel alloc] initWithFrame:CGRectZero];
    _researchLevel.frame = CGRectMake(padding, _researchTime.frame.origin.y + _researchTime.frame.size.height + 18, 70, 20);
    _researchLevel.font = [UIFont systemFontOfSize:16];
    _researchLevel.text = @"科研级别:";
    [_researchLevel setTextAlignment:NSTextAlignmentLeft];
    _researchLevel.textColor = [UIColor colorWithRed:102.0/255.0 green:102.0/255.0 blue:102.0/255.0 alpha:1.0];
    [self.view addSubview:_researchLevel];
    
    _inputresearchLevel = [[UITextField alloc] initWithFrame:CGRectMake(_researchLevel.frame.origin.x + _researchLevel.frame.size.width + 5,
                                                                        _researchLevel.frame.origin.y,
                                                                        self.view.frame.size.width - 80 - 10,
                                                                        20)];
    _inputresearchLevel.clearButtonMode = UITextFieldViewModeWhileEditing;
    _inputresearchLevel.textColor = [UIColor blackColor];
    _inputresearchLevel.returnKeyType = UIReturnKeyDone;
    _inputresearchLevel.placeholder = @"输入科研级别";
    [_inputresearchLevel setBackgroundColor:[UIColor clearColor]];
    _inputresearchLevel.delegate = self;
    _inputresearchLevel.font = [UIFont systemFontOfSize:16.0f];
    _inputresearchLevel.borderStyle = UITextBorderStyleNone;
    [self.view addSubview:_inputresearchLevel];
    
    // 科研简介
    _researchDesc = [[UILabel alloc] initWithFrame:CGRectZero];
    _researchDesc.frame = CGRectMake(padding, _researchLevel.frame.origin.y + _researchLevel.frame.size.height + 18, 70, 20);
    _researchDesc.font = [UIFont systemFontOfSize:16];
    _researchDesc.text = @"科研简介:";
    [_researchDesc setTextAlignment:NSTextAlignmentLeft];
    _researchDesc.textColor = [UIColor colorWithRed:102.0/255.0 green:102.0/255.0 blue:102.0/255.0 alpha:1.0];
    [self.view addSubview:_researchDesc];
    
    _inputresearchDesc = [[UITextField alloc] initWithFrame:CGRectMake(_researchDesc.frame.origin.x + _researchDesc.frame.size.width + 5,
                                                                       _researchDesc.frame.origin.y,
                                                                       self.view.frame.size.width - 80 - 10,
                                                                       20)];
    _inputresearchDesc.clearButtonMode = UITextFieldViewModeWhileEditing;
    _inputresearchDesc.textColor = [UIColor blackColor];
    _inputresearchDesc.returnKeyType = UIReturnKeyDone;
    _inputresearchDesc.placeholder = @"输入科研简介";
    [_inputresearchDesc setBackgroundColor:[UIColor clearColor]];
    _inputresearchDesc.delegate = self;
    _inputresearchDesc.font = [UIFont systemFontOfSize:16.0f];
    _inputresearchDesc.borderStyle = UITextBorderStyleNone;
    [self.view addSubview:_inputresearchDesc];
    
    // 科研备注
    _researchComment = [[UILabel alloc] initWithFrame:CGRectZero];
    _researchComment.frame = CGRectMake(padding, _researchDesc.frame.origin.y + _researchDesc.frame.size.height + 18, 70, 20);
    _researchComment.font = [UIFont systemFontOfSize:16];
    _researchComment.text = @"科研备注:";
    [_researchComment setTextAlignment:NSTextAlignmentLeft];
    _researchComment.textColor = [UIColor colorWithRed:102.0/255.0 green:102.0/255.0 blue:102.0/255.0 alpha:1.0];
    [self.view addSubview:_researchComment];
    
    _inputresearchComment = [[UITextField alloc] initWithFrame:CGRectMake(_researchComment.frame.origin.x + _researchComment.frame.size.width + 5,
                                                                          _researchComment.frame.origin.y,
                                                                          self.view.frame.size.width - 80 - 10,
                                                                          20)];
    _inputresearchComment.clearButtonMode = UITextFieldViewModeWhileEditing;
    _inputresearchComment.textColor = [UIColor blackColor];
    _inputresearchComment.returnKeyType = UIReturnKeyDone;
    _inputresearchComment.placeholder = @"输入科研备注";
    [_inputresearchComment setBackgroundColor:[UIColor clearColor]];
    _inputresearchComment.delegate = self;
    _inputresearchComment.font = [UIFont systemFontOfSize:16.0f];
    _inputresearchComment.borderStyle = UITextBorderStyleNone;
    [self.view addSubview:_inputresearchComment];
    
    [self initScrollView:_releaseArrImage];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

// 删除背景视图
- (void)removeBackView
{
    if (_backgroundView)
    {
        [_backgroundView removeFromSuperview];
        _backgroundView = nil;
    }
}

- (UIView*)topView
{
    UIViewController *recentView = self;
    
    while (recentView.parentViewController != nil)
    {
        recentView = recentView.parentViewController;
    }
    
    return recentView.view;
}

- (void)initScrollView:(NSMutableArray*)arrImage
{
    if (_imageScrollView)
    {
        [_imageScrollView removeFromSuperview];
    }
    
    _imageScrollView = [[UIScrollView alloc] initWithFrame:CGRectZero];
    _imageScrollView.frame = CGRectMake(0,
                                        _researchComment.frame.origin.y + _researchComment.frame.size.height + 130,
                                        [UIScreen mainScreen].bounds.size.width,
                                        70);
    _imageScrollView.directionalLockEnabled = YES; //只能一个方向滑动
    _imageScrollView.pagingEnabled = YES; //是否翻页
    _imageScrollView.backgroundColor = [UIColor clearColor];
    _imageScrollView.showsVerticalScrollIndicator = NO; //垂直方向的滚动指示
    _imageScrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;//滚动指示的风格
    _imageScrollView.showsHorizontalScrollIndicator = YES;//水平方向的滚动指示
    _imageScrollView.userInteractionEnabled = YES;
    _imageScrollView.delegate = self;
    [self.view addSubview:_imageScrollView];
    
    //设置滚动视图的位置
    [_imageScrollView setContentSize:CGSizeMake(([UIScreen mainScreen].bounds.size.width/5*(arrImage.count+1)),
                                                _imageScrollView.frame.size.height)];
    
    for (int i = 0; i < arrImage.count; i++)
    {
        NSData* data = [arrImage objectAtIndex:i];
        UIButton* imageBtnView = [[UIButton alloc] initWithFrame:CGRectMake(10*(i+1) + i*([UIScreen mainScreen].bounds.size.width-60)/5,
                                                                            0,
                                                                            ([UIScreen mainScreen].bounds.size.width-60)/5,
                                                                            ([UIScreen mainScreen].bounds.size.width-60)/5)];
        [imageBtnView setBackgroundColor:[UIColor redColor]];
        imageBtnView.contentMode = UIViewContentModeScaleAspectFill;
        //UIViewContentModeScaleAspectFit
        UIImage* image = [UIImage imageWithData:data];
        [imageBtnView setBackgroundImage:image forState:UIControlStateNormal];
        [_imageScrollView addSubview:imageBtnView];
    }
    
    NSInteger count = arrImage.count;
    UIButton* addBtn = [[UIButton alloc] initWithFrame:CGRectMake(10*(count+1) + count*([UIScreen mainScreen].bounds.size.width-60)/5,
                                                                  0,
                                                                  ([UIScreen mainScreen].bounds.size.width-60)/5,
                                                                  ([UIScreen mainScreen].bounds.size.width-60)/5)];
    addBtn.backgroundColor = [UIColor clearColor];
    [addBtn setBackgroundImage:[UIImage imageNamed:@"ic_add"] forState:UIControlStateNormal];
    [_imageScrollView addSubview:addBtn];
    [addBtn addTarget:self action:@selector(addImage) forControlEvents:UIControlEventTouchUpInside];
    [_imageScrollView addSubview:addBtn];
}

- (void)addImage
{
    FTPhotoAlbumController* phoAlbum = [[FTPhotoAlbumController alloc] init];
    phoAlbum.albumDelegate = self;
    phoAlbum.videoDelegate = self;
    phoAlbum.albumType = AlbumType_MutiForSending;
    ASBaseNavigationController* baseNavi = [[ASBaseNavigationController alloc] initWithRootViewController:phoAlbum];
    [self presentViewController:baseNavi animated:YES completion:nil];
}

- (void)selectHonorLevel:(NSString *)level
{
    //_inputHonorLevel.text = level;
    
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)rightButtonPressed:(id)action
{
    [self uploadSelectImages];
    //[self uploadResearchInfo];
}

// 上传选择的图片
- (void)uploadSelectImages
{
    // 上传图片接口 http://211.65.216.54/uploadAction.do?type=1&userCode=xiaohu
    // type=1 上传头像  2表示请假  3表示 发布成长   其他表示发布活动
    
    NSString* refer = @"uploadAction.do?type=3&userCode=";
    NSString* prefix = kASHttpUrl(refer);
    NSString* userCode = [ASAppDelegate sharedAppDelegate].userInfo.userCode;
    NSString* totalUrl = [prefix stringByAppendingString:userCode];
    
    // 提交信息上传
    NSString* achiTitle = _inputresearchName.text;     //论文名称
    NSString* achiType = _inputresearchType.text;      //期刊名称
    NSString* achiTime = _inputresearchTime.text;      //发表时间
    NSString* achiLevel = _inputresearchLevel.text;    //论文类别
    NSString* achiIntro = _inputresearchDesc.text;     //作者排名
    NSString* achiComment = _inputresearchComment.text;//论文描述
    
    NSString* infoUrl = [NSString stringWithFormat:@"&attr1=%@&condtionTypeId=%ld&attr2=%@&attr3=%@&attr4=%@&attr5=%@&attr6=%@&researchSubjectId=%@",
                          achiTitle,
                          (long)_typeID,
                          achiType,
                          achiTime,
                          achiLevel,
                          achiIntro,
                          achiComment,
                          _rTypeInfo.researchSubjectId];
    
    totalUrl = [totalUrl stringByAppendingString:infoUrl];
    
    [SVProgressHUD showWithStatus:@"上传图片..." maskType:SVProgressHUDMaskTypeClear];
    
    typeof(self) __weak weakSelf = self;
    ASNetworkEngine *netEngine = [ASNetworkEngine sharedInstance];
    [netEngine uploadImagesWithUrl:totalUrl image:_releaseArrImage progressBlock:^(long long bytesRead, long long totalBytes) {
        
    } completionBlock:^(id responseObject) {
        
        NSDictionary* jsonRsp = (NSDictionary *)responseObject;
        if (isSuccessRsp(jsonRsp))
        {
            [SVProgressHUD showSuccessWithStatus:@"新增成功"];
            
            [weakSelf popToListVC];
        }
        
    } failure:^(NSString *errorMsg) {
        
        [SVProgressHUD showErrorWithStatus:errorMsg.description];
    }];
}

- (void)uploadResearchInfo
{
    //发布用户状况的接口 http://211.65.216.54/addUserCondition.action?userCode=xiaohu&conditionDesc=asdasdasdasd&condtionTypeId=1&researchSubjectId=1&researchRemark=111&researchDesc=2222&researchSubjectId=1&conditionArea=111 condtionTypeId -1表示全部，1专业实习，2志愿服务，3社会实践，4其他 5奖惩 6科研 奖惩的时候 conditionUnit奖励单位 conditionLevel奖励级别字段 researchSubjectId科研类别researchRemark科研备注researchDesc可研描述conditionArea地点 conditionDesc状况的描述 2000汉字以内
    
    NSString* refer = @"addUserCondition.action?";
    NSString* prefix = kASHttpUrl(refer);
    NSString* userCode = [ASAppDelegate sharedAppDelegate].userInfo.userCode;
    NSString* achiTitle = _inputresearchName.text; //名称
    NSString* achiType = _inputresearchType.text; //类型
    NSString* achiTime = _inputresearchTime.text; //时间
    NSString* achiLevel = _inputresearchLevel.text; //级别
    NSString* achiComment = _inputresearchComment.text;//备注
    NSString* achiIntro = _inputresearchDesc.text;//简介
    
    NSString* totalUrl = [NSString stringWithFormat:@"%@userCode=%@&conditonTitle=%@&condtionTypeId=%ld&researchSubjectId=%@&conditionDate=%@&conditionLevel=%@&researchRemark=%@&researchDesc=%@",
                          prefix,
                          userCode,
                          achiTitle,
                          (long)_typeID,
                          achiType,
                          achiTime,
                          achiLevel,
                          achiComment,
                          achiIntro];
    
    typeof(self) __weak weakSelf = self;
    [SVProgressHUD showWithStatus:@"提交中..." maskType:SVProgressHUDMaskTypeClear];
    ASNetworkEngine *networkingEngine = [ASNetworkEngine sharedInstance];
    [networkingEngine GET:totalUrl parameters:nil success:^(id responseObject) {
        NSDictionary* jsonRsp = (NSDictionary *)responseObject;
        if (isSuccessRsp(jsonRsp))
        {
            NSString* retMsg = [jsonRsp objectForKey:kASJsonMsgData];
            
            if ([retMsg isEqualToString:@"新增成功"])
            {
                [SVProgressHUD showSuccessWithStatus:retMsg];
                
                [weakSelf popToListVC];
            }
            else
            {
                [SVProgressHUD dismiss];
            }
        }
        else
        {
            [SVProgressHUD showErrorWithStatus:errorMsgRsp(jsonRsp)];
        }
    } failure:^(NSError *error) {
        //[SVProgressHUD showErrorWithStatus:error.description];
        [SVProgressHUD showErrorWithStatus:@"网络异常，请稍后再试"];
    }];
}

- (void)popToListVC
{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - FTAlbumPhotoViewControllerDelegate

- (void)albumDidFinishPickingWithInfo:(NSMutableArray *)info
                          IsOriginImg:(BOOL)isOriginImg
                        withAlbumType:(AlbumType)albumType
{
    _releaseArrImage = info;
    [self initScrollView:_releaseArrImage];
    
    NSInteger offsetCount = 0;
    if (4 < _releaseArrImage.count)
    {
        offsetCount = _releaseArrImage.count-4;
        [_imageScrollView setContentOffset:CGPointMake(10*offsetCount + offsetCount*([UIScreen mainScreen].bounds.size.width-60)/5, 0)];
    }
}

#pragma mark - RCSVideoPickerDelegate
- (void)selectedVideoDictionary:(NSDictionary *)videoDic
                 pickController:(UIViewController *)ctr
                      videoData:(NSMutableArray*)videoData
{
}

#pragma mark - ASDatePickerViewDelegate

- (void)datePickerCancel
{
    [self removeBackView];
}

- (void)dataPickSelect:(NSInteger)selectTag selectDate:(NSString*)selectData
{
    NSString *strDate = selectData;
    NSRange range = [strDate rangeOfString:@" "];
    if (range.length > 0)
    {
        strDate = [strDate substringToIndex:range.location];
    }
    
    _inputresearchTime.text = strDate;
    
    [self removeBackView];
}

- (void)initDatePickerView
{
    _dateSelctPickerView = [[ASDatePickerView alloc] initWithFrame:CGRectMake(0,
                                                                              self.view.frame.size.height- 216 - 46,
                                                                              [UIScreen mainScreen].bounds.size.width,
                                                                              216 + 46)];
    _dateSelctPickerView.iTag = 0;
    _dateSelctPickerView.editTimeLab.text = @"选择日期";
    _dateSelctPickerView.delegate = self;
    _dateSelctPickerView.datePickerView.datePickerMode =UIDatePickerModeDate;
    //NSDate* minDate = [NSDate date];
    //_dateSelctPickerView.datePickerView.minimumDate = minDate;
    
    [self.view addSubview:_dateSelctPickerView];
}

#pragma mark - UITextFieldDelegate

- (BOOL)textFieldShouldReturn:(UITextField *)textField;
{
    [textField resignFirstResponder];
    
    return YES;
}

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    if (_inputresearchTime == textField)
    {
        UIView* sourceView = [self topView];
        _backgroundView = [[UIView alloc] initWithFrame:CGRectMake(0,
                                                                   0,
                                                                   sourceView.frame.size.width,
                                                                   sourceView.frame.size.height - 216 - 46)];
        [_backgroundView setBackgroundColor:[UIColor blackColor]];
        _backgroundView.alpha = 0.5;
        [sourceView addSubview:_backgroundView];
        [self initDatePickerView];
        
        return NO;
    }
    
    if (_inputresearchLevel == textField)
    {
        //论文类别
//        ASResearchLevelVC *rVC = [[ASResearchLevelVC alloc] init];
//        rVC.hidesBottomBarWhenPushed = YES;
//        rVC.delegate = self;
//        [self.navigationController pushViewController:rVC animated:YES];

        ASPaperTypeVC *pVC = [[ASPaperTypeVC alloc] init];
        pVC.hidesBottomBarWhenPushed = YES;
        pVC.delegate = self;
        [self.navigationController pushViewController:pVC animated:YES];
        return NO;
    }
    
    if (_inputresearchDesc == textField)
    {
        // 作者排名
        ASAuthorBankingVC *aVC = [[ASAuthorBankingVC alloc] init];
        aVC.hidesBottomBarWhenPushed = YES;
        aVC.delegate = self;
        [self.navigationController pushViewController:aVC animated:YES];
        
        return NO;
    }
    
    if (_inputresearchType == textField)
    {
//        ASResearchTypeVC *tVC = [[ASResearchTypeVC alloc] init];
//        tVC.hidesBottomBarWhenPushed = YES;
//        tVC.delegate = self;
//        [self.navigationController pushViewController:tVC animated:YES];
//        return NO;
    }
    
    return YES;
}

#pragma mark - ASResearchLevelVCDelegate
- (void)selectResearchLevel:(NSString *)level
{
    _inputresearchLevel.text = level;
    
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - ASResearchTypeVCDelegate
- (void)selectResearchType:(NSString *)type
{
    _inputresearchType.text = type;
    
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - ASPaperTypeVCDelegate

- (void)selectPaperType:(NSString *)type
{
    _inputresearchLevel.text = type;
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - ASAuthorBankingVCDelegate

- (void)selectAuthorBanking:(NSString *)aBanking
{
    _inputresearchDesc.text = aBanking;
    
    [self.navigationController popViewControllerAnimated:YES];
}



@end
